﻿namespace MyServer.Todo.Domain.Aggregates.TodoGroupAggregate
{
    public class TodoSettings : Entity
    {
        private TodoSettings()
        {

        }

        /// <summary>
        /// 创建默认TodoSettings
        /// </summary>
        /// <returns></returns>
        public static TodoSettings CreateDefaultSettings()
        {
            var settings = new TodoSettings();
            settings.GenerateId();
            return settings;
        }

        /// <summary>
        /// 到期时间
        /// </summary>
        public DateTime? ExpirationDate { get; private set; }

        /// <summary>
        /// 类别-标记待办事项颜色
        /// </summary>
        public TodoCategory Category { get; private set; }

        /// <summary>
        /// 是否是重要的
        /// </summary>
        public bool IsImportant { get; set; }

        /// <summary>
        /// 是否是我的一天
        /// </summary>
        public bool IsMyDay { get; set; }

        /// <summary>
        /// 今天到期
        /// </summary>
        public void DueToday()
        {
            var currentTime = DateTime.Now;
            SetExpirationDate(currentTime.Year, currentTime.Month, currentTime.Day);
        }

        /// <summary>
        /// 明天到期
        /// </summary>
        public void DueTomorrow()
        {
            var tomorrowDate = DateTime.Now.AddDays(1);
            SetExpirationDate(tomorrowDate.Year, tomorrowDate.Month, tomorrowDate.Day);
        }

        /// <summary>
        /// 设置截止日期
        /// </summary>
        public void SetExpirationDate(int year, int month, int day)
        {
            ExpirationDate = new DateTime(year, month, day);
        }

        /// <summary>
        /// 删除截止日期
        /// </summary>
        public void DeteleExpirationDate()
        {
            ExpirationDate = null;
        }

        /// <summary>
        /// 设置类别
        /// </summary>
        /// <param name="todoCategory"></param>
        public void SetCategory(TodoCategory todoCategory)
        {
            Category = todoCategory;
        }

        /// <summary>
        /// 添加到我的一天
        /// </summary>
        public void AddToMyDay()
        {
            IsMyDay = true;
        }

        /// <summary>
        /// 取消我的一天
        /// </summary>
        public void CancelMyDay()
        {
            IsMyDay = false;
        }

        /// <summary>
        /// 标记为重要
        /// </summary>
        public void MakeAsImportant()
        {
            IsImportant = true;
        }

        /// <summary>
        /// 取消重要标记
        /// </summary>
        public void CancelImportantMake()
        {
            IsImportant = false;
        }

        public TodoSettings Copy()
        {
            var todoSettings_copy = TodoSettings.CreateDefaultSettings();
            todoSettings_copy.ExpirationDate = this.ExpirationDate;
            todoSettings_copy.Category = this.Category;
            todoSettings_copy.IsMyDay = this.IsMyDay;
            todoSettings_copy.IsImportant = this.IsImportant;
            return todoSettings_copy;
        }
    }
}
